package com.googlecode.jmicroerp.service;

import com.googlecode.jmicroerp.model.Entitate;
import com.googlecode.jmicroerp.repository.GenericOrder;
import com.googlecode.jmicroerp.repository.GenericRepository;
import com.googlecode.jmicroerp.repository.GenericRestriction;
import java.io.Serializable;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author alex
 */
@Service(value = "genericService")
public class GenericService<T extends Entitate> implements Serializable {
    @Autowired
    private GenericRepository<T> genericRepository;
    
    public List<T> getList(Class<T> persistentClass, long firstResult, long maxResults, List<GenericRestriction> restrictions, List<GenericOrder> orders) {
        return genericRepository.getList(persistentClass, firstResult, maxResults, restrictions, orders);
    }
    
    public List<T> getList(Class<T> persistentClass, List<GenericRestriction> restrictions, List<GenericOrder> orders) {
        return genericRepository.getList(persistentClass, 0, Integer.MAX_VALUE, restrictions, orders);
    }
    
    public T getSingleResult(Class<T> persistentClass, GenericRestriction... restrictions) {
        return genericRepository.getSingleResult(persistentClass, restrictions);
    }
    
    public Long getCount(Class<T> persistentClass, GenericRestriction... restrictions) {
        return genericRepository.getCount(persistentClass, restrictions);
    }
    
    public T getById(Class<T> persistentClass, Long id) {
        return genericRepository.getById(persistentClass, id);
    }
    
    public void update(T entitate) {
        genericRepository.update(entitate);
    }
    
    public void insert(T entitate) {
        genericRepository.insert(entitate);
    }
    
    public void delete(T entitate) {
        genericRepository.delete(entitate);
    }
}
